import request from "@/utils/request";

const STOCKBILL_BASE_URL = "/api/v1/stockBills";

const StockBillAPI = {
  /** 获取账单分页数据 */
  getPage(queryParams?: StockBillPageQuery) {
    return request<any, PageResult<StockBillPageVO[]>>({
      url: `${STOCKBILL_BASE_URL}/page`,
      method: "get",
      params: queryParams,
    });
  },
  /**
   * 获取账单表单数据
   *
   * @param id 账单ID
   * @returns 账单表单数据
   */
  getFormData(id: number) {
    return request<any, StockBillForm>({
      url: `${STOCKBILL_BASE_URL}/${id}/form`,
      method: "get",
    });
  },

  /** 添加账单*/
  add(data: StockBillForm) {
    return request({
      url: `${STOCKBILL_BASE_URL}`,
      method: "post",
      data: data,
    });
  },

  /**
   * 更新账单
   *
   * @param id 账单ID
   * @param data 账单表单数据
   */
  update(id: number, data: StockBillForm) {
    return request({
      url: `${STOCKBILL_BASE_URL}/${id}`,
      method: "put",
      data: data,
    });
  },

  /**
   * 批量删除账单，多个以英文逗号(,)分割
   *
   * @param ids 账单ID字符串，多个以英文逗号(,)分割
   */
  deleteByIds(ids: string) {
    return request({
      url: `${STOCKBILL_BASE_URL}/${ids}`,
      method: "delete",
    });
  },
};

export default StockBillAPI;

/** 账单分页查询参数 */
export interface StockBillPageQuery extends PageQuery {
  /** 负债ID */
  debtId?: number;
  /** 状态 */
  status?: string;
}

/** 账单表单对象 */
export interface StockBillForm {
  /** 主键 */
  id?: number;
  /** 负债ID */
  debtId?: number;
  /** 账单还款日 */
  billDate?: Date;
  /** 账单还款金额 */
  billAmount?: number;
  /** 账单状态 */
  status?: string;
}

/** 账单分页对象 */
export interface StockBillPageVO {
  /** 主键 */
  id?: number;
  /** 负债ID */
  debtId?: number;
  /** 账单还款日 */
  billDate?: Date;
  /** 账单还款金额 */
  billAmount?: number;
  /** 账单状态 */
  status?: string;
}
